package com.zlp.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zlp.entity.RolePermissionRelation;
import com.zlp.mapper.RolePermissionRelationMapper;
import com.zlp.service.RolePermissionRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 后台用户角色和权限关系表 服务实现类
 * </p>
 *
 * @author LiPing.Zou
 * @since 2021-03-13
 */
@Service
@Slf4j(topic = "RolePermissionRelationServiceImpl")
public class RolePermissionRelationServiceImpl extends ServiceImpl<RolePermissionRelationMapper, RolePermissionRelation> implements RolePermissionRelationService {

    @Override
    public Boolean getRolePerByRoleIdAndPre(Long roleId, Long permissionId) {

        log.info("getRolePerByRoleIdAndPre.req roleId={}，permissionId={}", roleId, permissionId);
        RolePermissionRelation rolePermissionRelation = this.getOne(new QueryWrapper<>(new RolePermissionRelation()).
                eq("role_id", roleId).
                eq("permission_id", permissionId)
        );
        return Objects.nonNull(rolePermissionRelation) ? Boolean.TRUE : Boolean.FALSE;
    }
}
